/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.p10.miage.gestionabsence.action;

import fr.p10.miage.gestionabsence.form.PresenceActionForm;
import fr.p10.miage.gestionabsence.model.Etudiant;
import fr.p10.miage.gestionabsence.model.EtudiantBDD;
import fr.p10.miage.gestionabsence.model.SessionUtilisateur;
import fr.p10.miage.gestionabsence.model.Utilisateur;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;

/**
 *
 * @author huynal
 */
public class PresenceAction extends org.apache.struts.action.Action {

    /*
     * forward name="success" path=""
     */
    private static final String FAIL = "AbsenceDuJour";

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws  SQLException, Exception {
        
        ActionErrors errors = new ActionErrors();
        boolean resultat=false;
        Etudiant etudiant= null;

        etudiant= SessionUtilisateur.getEtudiant(request);

         if (etudiant!=null && etudiant instanceof Etudiant){
           /*try{
                resultat = EtudiantBDD.signalerPresenceCours(etudiant.getId(),);
            } catch (Exception ex) {
                errors.add("compte", new ActionMessage("errors.invalid", " Identifiant/Mot de passe"));
            }*/
        }
         else{
            errors.add("compte", new ActionMessage("errors.invalid", " Identifiant/Mot de passe"));
         }
         
         if(!errors.isEmpty()){
            this.saveErrors(request, errors);
         }

        return mapping.findForward(PresenceAction.FAIL);
    }
    
}
